package com.lanjiu.lib.imclient.dto.extra;

import com.lanjiu.pro.business.BusinessProtocolEntities;
import com.lanjiu.pro.business.BusinessProtocolMessages;
import com.lanjiu.lib.imclient.dto.FriendDto;
import com.lanjiu.lib.imclient.dto.base.Dto;
import com.lanjiu.lib.imclient.dto.chat.ChatMessageDto;
import com.lanjiu.lib.imclient.ims.IMSContacts;
import com.lanjiu.lib.imclient.user.UserPreferences;

/**
 * @description:
 * @author: Panwei
 * @date: 2019/11/18 15:26
 */
public class ChatFriendMsgDto extends Dto {

    private FriendDto friendDto;

    private ChatMessageDto chatMessageDto;

    public ChatFriendMsgDto() {
    }

    public ChatFriendMsgDto(FriendDto friendDto, ChatMessageDto chatMessageDto) {
        this.friendDto = friendDto;
        this.chatMessageDto = chatMessageDto;
    }

    public FriendDto getFriendDto() {
        return friendDto;
    }

    public void setFriendDto(FriendDto friendDto) {
        this.friendDto = friendDto;
    }

    public ChatMessageDto getChatMessageDto() {
        return chatMessageDto;
    }

    public void setChatMessageDto(ChatMessageDto chatMessageDto) {
        this.chatMessageDto = chatMessageDto;
    }

    @Override
    public BusinessProtocolMessages.FriendChatProtocol toProtobuf() {
        BusinessProtocolMessages.FriendChatProtocol.Builder friendChatProtocolBuilder = BusinessProtocolMessages.FriendChatProtocol.newBuilder();
        if (null != friendDto) {
            if (IMSContacts.UserType.TOURISTS_USER.equals(friendDto.getCurrentUserType())) {
                friendChatProtocolBuilder.setUserType(IMSContacts.UserType.TOURISTS_USER);
                friendChatProtocolBuilder.setTouristsUser(BusinessProtocolEntities.TouristsUser.newBuilder()
                        .setTemporaryId(UserPreferences.getUserId())
                        .setNickname(UserPreferences.getNickname())
                        .setAvatar(UserPreferences.getAvatar())
                        .build());
                friendChatProtocolBuilder.setTouristsFriend((BusinessProtocolEntities.TouristsFriend) friendDto.toProtobuf());
            } else {
                friendChatProtocolBuilder.setUserType(IMSContacts.UserType.REGISTERED_USER);
                friendChatProtocolBuilder.setRegisteredUser(BusinessProtocolEntities.RegisteredUser.newBuilder()
                        .setUserId(UserPreferences.getUserId())
                        .setNickname(UserPreferences.getNickname())
                        .setAvatar(UserPreferences.getAvatar())
                        .build());
                friendChatProtocolBuilder.setRegisteredFriend((BusinessProtocolEntities.RegisteredFriend) friendDto.toProtobuf());
            }
        }
        if (null != chatMessageDto)
            friendChatProtocolBuilder.setChatMessage(chatMessageDto.toProtobuf());
        return friendChatProtocolBuilder.build();
    }
}
